################################
# setup and proc
# ##############################
source -e -v user_scripts/global_setup.tcl
source -e -v user_scripts/block_setup.tcl
source -e -v user_scripts/loadInnovus.tcl

set current_step "ccopt"
set previous_step "place"

set report_dir "reports/${current_step}"
if {![file exist $report_dir]} {file mkdir $report_dir}

#####################################
# open design
# ##################################
restoreDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${previous_step}.dat $DESIGN_NAME

# common setting
source -e -v user_scripts/common_setting.tcl
#source -e -v user_scripts/common_setting_multicycle.tcl



############################################
# cts setting
############################################
source -e user_scripts/common_setting.ccopt.tcl

############################################
#Pre-place customizations
############################################
if {[file exists $PRE_SCRIPT($current_step)]} {
		puts "INFO: Sourcing $PRE_SCRIPT($current_step)"
		source $PRE_SCRIPT($current_step)
} else {
		puts "WARN: $PRE_SCRIPT($current_step) not exist. Skip to source it."
}


############################################
# Core command
############################################
setOptMode -addInstancePrefix CCOPT
setOptMode -addNetPrefix CCOPT_NET
#setOptMode -usefulSkewPreCTS true
create_ccopt_clock_tree_spec -file $DESIGN_NAME.ccopt.spec
source $DESIGN_NAME.ccopt.spec
if {[file exists $USER_CCOPT_SPEC_FILE]} {
		puts "INFO: Sourcing $USER_CCOPT_SPEC_FILE"
		source $USER_CCOPT_SPEC_FILE
} else {
		Puts "WRAN: $USER_CCOPT_SPEC_FILE not exist. Skip to source it."
}

ccopt_design

source -e -v user_scripts/pg_connection.tcl

#saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.ccopt_design_${current_step}


############################################
# propagate all clocks
############################################
set_interactive_constraint_modes [all_constraint_modes -active]
set_propagated_clock [all_clocks]
set_interactive_constraint_modes {}

if {$ROUTE_OPT_FIX_HOLD} {
		puts "INFO: enable incremetal setup and hold fix after ccopt"
		optDesign -postCTS -setup -hold -drv
#		optDesign -postRoute -hold
} else {
		puts "INFO: ebabel incremetal setup opt after ccopt"
		optDesign -postCTS -setup
}

############################
# PG connection
# ##########################
source -e -v user_scripts/pg_connection.tcl


#####################################
# Post-ccopt customizations
# ##################################
if {[file exists $POST_SCRIPT($current_step)]}  {
		puts "INFO: Sourcing $POST_SCRIPT($current_step)"
		source $POST_SCRIPT($current_step)
} else {
		puts "WARN: $POST_SCRIPT($current_step) not exist. Skip to source it."
}


saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${current_step}


###################################################
# Report
# ##############################################
if {$REPORT_QOR($current_step)} {
		source -e ./user_scripts/report_qor.tcl
} else {
		puts "INFO: Skip report for step: $current_step"
}

date > ${current_step}

exit






